package com.ziki.bswicket.panel;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.AbstractLink;
import org.apache.wicket.markup.html.list.LoopItem;
import org.apache.wicket.markup.html.navigation.paging.IPageable;
import org.apache.wicket.markup.html.navigation.paging.IPagingLabelProvider;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigation;

import com.ziki.framework.wicket.markup.html.FwContainer;

public class BsPagingNavigation extends PagingNavigation {

    private static final long serialVersionUID = 1L;

    public BsPagingNavigation(String id, IPageable pageable) {
        super(id, pageable);
    }

    public BsPagingNavigation(String id, IPageable pageable, IPagingLabelProvider labelProvider) {
        super(id, pageable, labelProvider);
    }

    @Override
    protected void populateItem(final LoopItem loopItem) {
        // Get the index of page this link shall point to
        final long pageIndex = getStartIndex() + loopItem.getIndex();

        // Add a page link pointing to the page
        final AbstractLink link = newPagingNavigationLink("pageLink", pageable, pageIndex);
        loopItem.add(link);
        if (pageable.getCurrentPage() == pageIndex){
            FwContainer span = new FwContainer("");
        }

        // Add a page number label to the list which is enclosed by the link
        String label = "";
        if (labelProvider != null) {
            label = labelProvider.getPageLabel(pageIndex);
        } else {
            label = String.valueOf(pageIndex + 1);
        }
        link.add(new Label("pageNumber", label));
    }
}
